package org.frv.wispr.web.account;

import org.apache.wicket.security.hive.authentication.LoginContext;
import org.apache.wicket.security.hive.authentication.Subject;
import org.apache.wicket.security.hive.authentication.DefaultSubject;
import org.apache.wicket.security.strategies.LoginException;

/**
 * Created by IntelliJ IDEA.
 * User: frank
 * Date: Jan 8, 2008
 * Time: 11:14:35 PM
 * To change this template use File | Settings | File Templates.
 */
public class UserContext extends LoginContext {
    private String username;
    String password;

    public UserContext(String username, String password) {
 		super();
		this.username=username;
		this.password=password;
 	}


    public Subject login() throws LoginException {
		//the context is a disposable object, we explicitly check that here, but it is not required
		if(username == null || password == null) {
            throw new LoginException("Can not reuse this context");
        }

        // do actual authentication here, but for now everything is cool
        DefaultSubject user=new DefaultSubject();
        user.addPrincipal(new UserPrincipal("basic"));

		this.username=null;
		this.password=null;
		return user;
 	}

}
